﻿using AutoMapper;
using B.S.BasicData.Domain.Entities;
using B.S.BasicData.Error;
using B.S.BasicData.Infrastructure.InProfaces;
using B.S.BasicData.Read.Api.Application.Command.ShopCommand;
using MediatR;

namespace B.S.BasicData.Read.Api.Application.CommandHander.ShopCommandHander
{
    public class ShopQueryCommandHander : IRequestHandler<ShopQueryCommand, ApiResult<List<Shop>>>
    {
        private readonly IBaseRepository<Shop> ShopRepository;

        public ShopQueryCommandHander(IBaseRepository<Shop> shopRepository)
        {
            ShopRepository = shopRepository;
        }

        public Task<ApiResult<List<Shop>>> Handle(ShopQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Shop>> result = new ApiResult<List<Shop>>();

            var list = ShopRepository.GetAll();


            result.Code = ApiEnum.success;
            result.Msg = "查询成功";
            result.Data = list.ToList();

            return Task.FromResult(result);
        }
    }
}
